<?php
/**
* @package Pages-and-Items (com_pi_pages_and_items)
* @version 1.5.7
* @copyright Copyright (C) 2006-2010 Carsten Engel. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* @author http://www.pages-and-items.com
*/

//no direct access
if(!defined('_VALID_MOS') && !defined('_JEXEC')){
	die('Restricted access');
}


//check user right to move a page
if($class_pi->checkUserActionRight(7)!=true){
	echo '<script> alert(\''._pi_lang_no_move_page.'\'); window.history.go(-1); </script>';
	exit();	
}	
		
foreach($class_pi->menuitems as $row){
	if($row->id==$pageId){
		$name = $row->name;					
		$parent = $row->parent;	
		$menutype = $row->menutype;			
	}
}
	
echo "<link href=\"components/com_pi_pages_and_items/css/pages_and_items3.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
echo "<link href=\"components/com_pi_pages_and_items/css/dtree.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
echo "<script src=\"components/com_pi_pages_and_items/javascript/dtree.js\" language=\"JavaScript\" type=\"text/javascript\"></script>\n";
echo "<script src=\"../includes/js/overlib_mini.js\" language=\"JavaScript\" type=\"text/javascript\"></script>\n";

//give headers in Joomla 1.5 a bit more spunk
$class_pi->spunk_up_headers_1_5();

?>
<script language="JavaScript" type="text/javascript">
<!--

function select_parent(parent_id, new_menutype){
	document.getElementById('new_parent_id').value = parent_id;	
	document.getElementById('new_menutype').value = new_menutype;	
}

function dont_move_here(){
	alert('<?php echo _pi_lang_nomoveundersamepage; ?>');
	document.getElementById('new_parent_id').value = '';		
}

function submitbutton(pressbutton) {
	if (pressbutton == 'cancel') {
		submitform( pressbutton );
		<?php
			if( defined('_JEXEC') ){			
			//echo '1.5';
			$live_path = $mainframe->getCfg('live_site');
			}else{			
			//echo '1.0.x';
			$live_path = $mosConfig_live_site;
			}		
		?>
		old_parent_id = document.getElementById('old_parent_id').value;		
		document.href = 'index2.php?option=com_pi_pages_and_items&task=item&sub_item=edit&pageId='+old_parent_id;
		return;		
	}
	if (pressbutton == 'page_move_save') {	
		if (document.adminForm.new_parent_id.value == '' ) {			
			alert( '<?php echo _pi_lang_havetoselectparentpage; ?>' );
			return;
		} else {
			submitform(pressbutton);			
		}
	}
}


-->
</script>

<table cellspacing="0" cellpadding="0" border="0" width="100%">
  <tr>
    <td valign="top" width="25%"><?php
		$class_pi->pages();
		?></td> 
    <td valign="top">
		<form name="adminForm" method="post" action="">
			<input type="hidden" name="option" value="com_pi_pages_and_items" />
			<input type="hidden" name="task" value="page_move_save" />				
			<input type="hidden" name="pageId" value="<?php echo $pageId; ?>">
			<input type="hidden" name="new_menutype" id="new_menutype" value="">
			<input type="hidden" name="old_menutype" value="<?php echo $menutype; ?>">
			<input type="hidden" name="old_parent_id" id="old_parent_id" value="<?php echo $parent; ?>" />
			<input type="hidden" value="" id="new_parent_id" name="new_parent_id" />
			<div id="pi_breadcrumb">
				<a href="index2.php?option=com_pi_pages_and_items&amp;task=page&amp;sub_task=edit&amp;pageId=<?php echo $pageId; ?>"><?php echo _pi_lang_page; ?></a> >  <?php echo _pi_lang_pagemove; ?>
			</div>			
		 
		   <table class="adminform">
			<tr>
				<th>
					 <?php echo _pi_lang_movepage; ?>: "<?php echo $name ?>"
				</th>
			</tr>
				<tr>
					<td>		
						<p><?php echo _pi_lang_whenmovingpage; ?></p>
						<p><?php echo _pi_lang_selectpageunder; ?></p>						 
					</td>
				</tr>
				<tr>
					<td>
						<?php
						
						//see how many loops we need
						$loops = count($class_pi->menutypes);						
					
						//loop menutypes
						for($m = 0; $m < $loops; $m++){	
						
							echo '<div class="dtree">';					
							
							echo '<p><a href="javascript: pages_tree'.$m.'.openAll();">'._pi_lang_open_all.'</a> | <a href="javascript: pages_tree'.$m.'.closeAll();">'._pi_lang_close_all.'</a></p>';
							
							//open javascript
							echo "<script type=\"text/javascript\"  type=\"text/javascript\">\n";
							echo "<!--\n";
							echo "pages_tree$m = new dTree('pages_tree$m');\n";						
							echo "pages_tree$m.add(0,-1,'";
							echo $class_pi->get_menutype_title($class_pi->menutypes[$m]);							
							echo "','javascript:select_parent(0,\'".$class_pi->menutypes[$m]."\');','','','','',true);\n";
						
							//make javascript-array from main-menu-items
							foreach($class_pi->menuitems as $row){
								$show_item = false;								
								if($row->menutype==$class_pi->menutypes[$m]){
									$show_item = true;
								}								
								if($show_item){
									echo "pages_tree$m.add(".$row->id.",".$row->parent.",'".(addslashes($row->name))."','";
									if($row->id!=$pageId && $row->parent!=$pageId){								
										echo "javascript: select_parent(".$row->id.",\'".$class_pi->menutypes[$m]."\');";
									}else{
										echo '';
									}
									if(((strstr($row->link, 'index.php?option=com_content&view=category&layout=blog') && $row->type=='url') || !strstr($row->link, 'index.php?option=com_content&view=category&layout=blog')) && $row->type!='content_blog_category'){
										echo "','','','components/com_pi_pages_and_items/images/link.gif','components/com_pi_pages_and_items/images/link.gif";		
									}else{
										echo "','','','components/com_pi_pages_and_items/images/page.gif','components/com_pi_pages_and_items/images/page.gif";		
									}
									echo "');\n";
								}	
							}						
						   
							echo "document.write(pages_tree$m);\n";					
						
							//close javascript
							echo "//-->\n";
							echo "</script>\n";
							echo '</div>';
							
						}//end menutypes loop
						?>
							
					</td>
				</tr>
			</table>
		</form>
	</td>
  </tr>
</table>
<?php
	$class_pi->display_footer();
?>	
			
		